<%@ include file="/WEB-INF/jsp/include/taglib.jsp" %>

<h1>
    <a href="<c:url value="/forum.form"/>">
        <fmt:message key="app.forum.topic.list"/>
    </a>
    : <c:out value="${entry.header}"/>
</h1>

<authz:authorize ifAnyGranted="ROLE_SUPERVISOR">
    <a href="<c:url value="/system/addtopic.form"/>">
        <fmt:message key="app.forum.topic.add"/>
    </a>
</authz:authorize>
<a href="<c:url value="/addpost.form/${entry.id}"/>">
    <fmt:message key="app.forum.post.add"/>
</a>

<c:set var="isSupervisor" value="false"/>

<authz:authorize ifAllGranted="ROLE_SUPERVISOR">
    <c:set var="isSupervisor" value="true"/>
</authz:authorize>

<c:forEach items="${entry.posts}" var="post">
    <c:if test="${!post.hidden || isSupervisor}">
        <div class="entry">
            <div class="entry-left">
                <img src="/static-images/pic-post.gif">
            </div>
            <div class="entry-right">
                <c:choose>
                    <c:when test="${post.author.blocked}">
                        <div class="entry-header">
                            <fmt:message key="app.forum.post.blocked"/> (${post.header})
                        </div>
                        <div class="entry-data">
                            <s>
                                <fmt:message key="app.forum.author"/>: <b><c:out value="${post.author.username}"/></b>
                                <fmt:message key="app.forum.date"/>: <b>
                                <fmt:formatDate type="both" value="${post.date}"/>
                            </b>                                
                                <fmt:message key="app.forum.post.commentscount"/>: <b><c:out
                                    value="${post.commentCount}"/></b>
                            </s>
                        </div>
                        <div class="entry-text">
                            &nbsp;
                        </div>
                    </c:when>
                    <c:otherwise>
                        <div class="entry-header">
                            <a href="<c:url value="/post.form/${post.id}"/>">
                                <c:out value="${post.header}"/>
                            </a>
                        </div>
                        <div class="entry-data">
                            <fmt:message key="app.forum.author"/>:
                            <a href="<c:url value="/viewprofile.form/${post.author.username}"/>"><b>${post.author.username}</b></a>

                            <fmt:message key="app.forum.date"/>: <b>
                            <fmt:formatDate type="both" value="${post.date}"/>
                        </b>
                            <fmt:message key="app.forum.post.commentscount"/>: <b><c:out
                                value="${post.commentCount}"/></b>
                            <authz:authorize ifAllGranted="ROLE_SUPERVISOR">
                                (<fmt:message key="app.forum.post.state.${post.state}"/>)
                            </authz:authorize>
                        </div>
                        <div class="entry-text">
                                ${post.text}
                            <br/>
                        </div>
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
    </c:if>
</c:forEach>
